<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ page import="hk.hku.hooku.db.*"%>
<%@ page import="hk.hku.hooku.pojo.*" %>
<%@ page import="hk.hku.hooku.util.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Map.*" %>
<%@ page import="java.sql.Timestamp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="js/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="js/eventInit.js" ></script>
<%
	String email=(String)request.getSession().getAttribute("loginUser");
    boolean is_load = true;
    if(email==null||email.isEmpty()){
    	email="";
    	is_load=false;
    }
    	
    
    ArrayList<String> contactlist = null;
    if(is_load)
    {
        contactlist = ContactDB.getContactByEmail(email);
    //    for(int i = 0; i < 5; i++)
    //    	contactlist.add("junx"+i);
        /* if(contactlist.isEmpty())
        	is_load = false; */
    }

    Entry<Integer, String> event_id_url = EventDB.generateRandomUrl();
    String event_url = event_id_url.getValue();
    int event_id = event_id_url.getKey();
    ArrayList<String> email_list = EventDB.getMailToList(event_id);
    Timestamp current_day_time = new Timestamp(System.currentTimeMillis());
    
    int cur_year = current_day_time.getYear()+1900;
    String cur_year_s = String.valueOf(cur_year);
    
    int cur_month = current_day_time.getMonth()+1;
    String cur_month_s = String.valueOf(cur_month);
    if(cur_month < 10)
    	cur_month_s = "0"+cur_month_s;
    
	int cur_day = current_day_time.getDate();
	String cur_day_s = String.valueOf(cur_day);
	if(cur_day < 10)
		cur_day_s = "0"+cur_day_s;
	
	String date = cur_year_s+"-"+cur_month_s+"-"+cur_day_s;
	   
    int cur_hour = current_day_time.getHours();
    String cur_hour_s = String.valueOf(cur_hour);
    if(cur_hour < 10)
    	cur_hour_s = "0"+cur_hour_s;
    
    int cur_minute = current_day_time.getMinutes();
    String cur_minute_s = String.valueOf(cur_minute);
    if(cur_minute < 10)
    	cur_minute_s = "0"+cur_minute_s;
    
    String time = cur_hour_s+":"+cur_minute_s;
    
    String cur_time = date+"*"+time+":00";
%>

<title>Hooku Event</title>

<link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/event_create.css" />

</head>

<body>

<p id="hidden_content" hidden>
    <input id="hidden_url" type="text" value = <%=event_url %>>
    <input id="hidden_id" type="text" value = <%=event_id %>>
    <input id="hidden_time" type="text" value = <%=cur_time %>>
    <input id="hidden_count" type = "text" value ="1">
</p>

<!--header -->
<div id="header-wrap"><div id="header">
	<h1 id="logo-text"><a href="eventCreate.jsp" title="">Hooku</a></h1>
	<p id="slogan">To Make the Easiest Arragements </p>


<!--/header-->
</div></div>
<!-- content-outer -->
<div id="content-wrap" class="clear" >

	<!-- content -->
   <div id="content">

   	<!-- main -->
	   <div id="main">
            <div class="post-bottom-section">

            <div class="right">
				<p><h2>Arrangement</h2></p>
            	<form  method="post" id="commentform">
                <p>
                            <label>Email</label><br />
                            <input id = "proposer_email" class="" name="proposer_email" type = "text" tbaindex = "2" value="<%= email%>"/>
                        </p>
               	<p>
					 		<label for="title">Title (required)</label><br />
							<input id="title" name="title" type="text" tabindex="3"/>
						</p>
                  <p>
						 	<label for="location">Location (required)</label><br />
							<input id="location" name="location" type="text" tabindex="4"/>
						</p>
                  <p>
							<label for="description">Description</label><br />
							<textarea id="description" name="description" rows="4" cols="20" type="text" tabindex="5"></textarea>
						</p>
						
				<p class="no-border">
				<label for="event_choice" >Time Slots</label><br />
				<div id="event_choice_Table_div">
				<table >
					<thead>
					</thead>
					<tbody id="event_choice_body">
					    <tr id="event_choice_date">
							<th class="event_choice_outer_head">Year-Month-Day</th>
							<td  class="event_choice_outer"  id = "event_choice1_1"><input type="text"  class="event_choice_inner1" id = "event_choice_date_1" value=<%=date %>></td>												
						</tr>
					    <tr id="event_choice_start">
					        <th class="event_choice_outer_head">Start Hour:Minute</th>
					        <td  class="event_choice_outer"  id = "event_choice2_1"><input type="text"  class="event_choice_inner2" id = "event_choice_start_1" value=<%=time %>></td>
					    </tr>
					    <tr id="event_choice_end">
					        <th  class="event_choice_outer_head">End Hour:Minute</th>
					        <td  class="event_choice_outer"  id = "event_choice3_1"><input type="text"  class="event_choice_inner3" id = "event_choice_end_1" value=<%=time %>></td>
					    </tr>
					</tbody>
					<tfoot>
                        <tr id="event_choice_remove">
                            <th class = "event_choice_outer_head"></th>
                            <td  class="event_choice_outer" id = "event_choice4_1"><input type="button" class="event_choice_inner" value="remove" id = "event_choice_remove_1"/></td>
                        </tr>
                    </tfoot>
				</table>
				</div>
				&nbsp;&nbsp;&nbsp;<input type="button" class="button" value="add" id = "add_event_choice_Button"/>
			</p>
			
			    <p class="no-border">
				<label for="all" >Receiver</label><br />
				
			<%if(is_load)
			{%>
				<div id="all_Table_div">
				<table >
					<thead>
						<tr>
							<th id = "receiver_email_id">Receivers</th>
							<th class = "table_column_spacing"></th>
							<th id = "receiver_remove_id">Select email from contacts</th>
						</tr>
						<tr>
						    <td>
							    <div id="receiver_Table_div">
			                	<table >
				        		    <thead>
				        	    	</thead>
			        		     	<tbody id="receiver_Table_body">
				        		        <tr id = "tr_1">
				        		        <td><input type="text"  class="receiver_email_class" id = "receiver_email_1" value=""></td>
				        		        <td><input type="button" class="receiver_remove_class" value="remove" id = "receiver_remove_1"/></td>
				        		    </tr>
				        	        </tbody>
			        		    </table>
			        	    	</div>
							</td>
							<th class = "table_column_spacing"></th>
							<td>
						    	<div id="contact_Table_div">
					    		<table >
					    			<thead>
						    		</thead>
						    	  	<tbody id="contact_Table_body" >
						    		        <% for(int i = 1; i <= contactlist.size(); i++)
						    		        {
						    		        	String cid = "contact_email_"+i;
						    		        	String aid = "contact_add_"+i;
						    		        	String fun = "contactAddFunction('"+contactlist.get(i-1)+"')";
						    		        %>
						    		        <tr id = "tr1_1">
						    		        <td><input type="text"  class="contact_email_class" id = <%=cid %> value=<%=contactlist.get(i-1) %>></td>
							    	        <td><input type="button" onclick = <%=fun %> class="contact_add_class" id = <%=aid %> value="add"></td>
							    	        </tr>
							    	        <%} %>
						    	    </tbody>
					    		</table>
					    		</div>
					    	</td>
						</tr>
					</thead>
				</table>
				</div>
				&nbsp;&nbsp;&nbsp;<input type="button" class="button" value="Add" id="add_receiver_Button1" />
		   <%} else{%>
		        <div id="receiver_Table_div">
		        <table >
				     <thead>
				     <tr>
				         <th><label>Email</label><br /></th>
				         <th><label>Remove</label><br /></th>
				     </tr>
				     </thead>
			         <tbody id="receiver_Table_body">
				        <tr id = "tr_1">
				        	<td><input type="text"  class="receiver_email_class_2" id = "receiver_email_1" value=""></td>
				        	<td><input type="button" class="receiver_remove_class" value="remove" id = "receiver_remove_1"/></td>
				        </tr>
				     </tbody>
			    </table>
		        </div>
				&nbsp;&nbsp;&nbsp;<input type="button" class="button" value="Add" id="add_receiver_Button2" />
		   <%} %>
			</p>
			 <p class="no-border" id="buttonDiv">
	<input type="button" class="button" value="      Save     " id="save_Button" />
	&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" class="button" value="Save and Send" id="save_send_Button" />
					
						</p>
			<p class="no-border" id="messageDiv" hidden></p>
               </form>

            </div>

         </div>

        <!-- /main -->
		</div>

      <!-- sidebar -->
		<div id="sidebar">
		    <%if(is_load)
		    	{
		    	   String homeurl = "eventlist.jsp"; %>
		    	<div class="homepage">
				<h3>
				<a href= <%=homeurl %>>HomePage</a>
				</h3>
			</div>
			<%} %>
			
			<div class="sidemenu">
				<h3>Poll Link</h3>
				<p>
					<input id="pollLink" type="text" value="http://<%=Config.HOST %>/eventVote.jsp?url=<%=event_url %>"/>
				</p>
			</div>
			
			<div class="sidemenu">
				<h3>Manage Link</h3>
				<p>
					<a href="event.jsp?url=<%=event_url %>">Manage The Event here</a>
				</p>
			</div>
			
			
			
			<div class="about-me">

         	<h3>About Us</h3>
		      <p>
		      <a href="http://www.cs.hku.hk/~fliang"><img src="images/hku.png" width="40" height="40" alt="firefox" class="float-left" /></a>
            We are an innovative and enthusiastic team from the CS department of The University of Hong Kong.   <a href="http://www.cs.hku.hk/~fliang">Learn more...</a>
				</p>

         </div>

      <!-- /sidebar -->
		</div>

    <!-- content -->
	</div>

<!-- /content-out -->
</div>

<!-- footer-bottom -->
<div id="footer-bottom">

	<p class="bottom-left">
		&copy; 2013 <strong>Copyright Info</strong>&nbsp; &nbsp; &nbsp;
		<a href="http://www.cs.hku.hk/~fliang" title="homepage">Hooku</a> from <a href="http://www.cs.hku.hk/~fliang">HKU</a>
	</p>

	<p class="bottom-right">
		<a href="index.html">Home</a> |
      <strong><a href="#top">Back to Top</a></strong>
   </p>

<!-- /footer-bottom-->
</div>

</body>
</html>
